bitkeeper revision 1.1159.187.58 (41b88ba7ZjuJcwYxAL5HR5J_1FXMYw)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 9 Dec 2004 17:30:15 +0000 (17:30 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 9 Dec 2004 17:30:15 +0000 (17:30 +0000)
sysrq hacks from Matt Bloch

.rootkeys
linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c
tools/python/xen/xend/XendClient.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/server/SrvDaemon.py
tools/python/xen/xend/server/SrvDomain.py
tools/python/xen/xend/server/domain.py
tools/python/xen/xend/server/messages.py
tools/python/xen/xm/main.py
tools/python/xen/xm/sysrq.py [new file with mode: 0644]

index 44aaa3ca194ace48efe462991738b01168643aaf..87bb718abb56d1fc1f5f2d271579663ac17a9407 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 411b2c1ehdEGO_CwG0tvn85Q-Tfh5g tools/python/xen/xm/migrate.py
 40cf2937PSslwBliN1g7ofDy2H_RhA tools/python/xen/xm/opts.py
 40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/python/xen/xm/shutdown.py
+41b88ba6_C4---jeA895Efg9YFZgKA tools/python/xen/xm/sysrq.py
 40fcefb2K1xqVVT4D-p7nL2GzS4scg tools/sv/Main.rpy
 40ffbcb66Dj5F-1kCK9BcgSqCWkt1w tools/sv/Makefile
 4120b0e5L_nW-u0MWRfIdXg4ng4OjA tools/sv/images/destroy.png
index 1f7303efd2f4cf5f09db459c3fa08d6f684cb3b8..78c46675f533815ff8810053a0ba20b209371288 100644 (file)
@@ -8,6 +8,7 @@ static int errno;
 #include <linux/unistd.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
+#include <linux/sysrq.h>
 #include <asm/irq.h>
 #include <asm/mmu_context.h>
 #include <asm-xen/ctrl_if.h>
@@ -49,10 +50,9 @@ EXPORT_SYMBOL(machine_power_off);
  * Stop/pickle callback handling.
  */
 
-//#include <asm/suspend.h>
-
 /* Ignore multiple shutdown requests. */
 static int shutting_down = -1;
+static int pending_sysrq = -1;
 
 static void __do_suspend(void)
 {
@@ -214,9 +214,18 @@ static void __shutdown_handler(void *unused)
     }
 }
 
+static void __sysrq_handler(void *unused)
+{
+#ifdef CONFIG_MAGIC_SYSRQ
+    handle_sysrq(pending_sysrq, NULL, NULL);
+#endif
+    pending_sysrq = -1;
+}
+
 static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
 {
     static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
+    static DECLARE_WORK(sysrq_work, __sysrq_handler, NULL);
 
     if ( (shutting_down == -1) &&
          ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
@@ -226,6 +235,12 @@ static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
         shutting_down = msg->subtype;
         schedule_work(&shutdown_work);
     }
+    else if ( (pending_sysrq == -1) && 
+              (msg->subtype == CMSG_SHUTDOWN_SYSRQ) )
+    {
+        pending_sysrq = msg->msg[0];
+        schedule_work(&sysrq_work);
+    }
     else
     {
         printk("Ignore spurious shutdown request\n");
index 8290165412f48a77c595a2efa9ad4f4e9eb23cd3..91efd5cc8e86fbbed0ab02a24b5844cc606d7c17 100644 (file)
@@ -228,10 +228,11 @@ class Xend:
         return self.xendPost(self.domainurl(id),
                              {'op'      : 'pause' })
 
-    def xend_domain_shutdown(self, id, reason):
+    def xend_domain_shutdown(self, id, reason, key=None):
         return self.xendPost(self.domainurl(id),
                              {'op'      : 'shutdown',
-                              'reason'  : reason })
+                              'reason'  : reason,
+                              'key'     : key })
 
     def xend_domain_destroy(self, id, reason):
         return self.xendPost(self.domainurl(id),
index fc53b4de03cea3f097e8e1dd7b85563e1c359490..4e614af54e1fec0d11bc04e987dcbc4f3fbb3dec 100644 (file)
@@ -455,7 +455,7 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
     
-    def domain_shutdown(self, id, reason='poweroff'):
+    def domain_shutdown(self, id, reason='poweroff', key=None):
         """Shutdown domain (nicely).
          - poweroff: restart according to exit code and restart mode
          - reboot:   restart on exit
@@ -474,7 +474,7 @@ class XendDomain:
         eserver.inject('xend.domain.shutdown', [dominfo.name, dominfo.id, reason])
         if reason == 'halt':
             reason = 'poweroff'
-        val = xend.domain_shutdown(dominfo.id, reason)
+        val = xend.domain_shutdown(dominfo.id, reason, key)
         self.refresh_schedule()
         return val
 
index 05a0f27201dc453b02e5cb6f68cd3da5351703c8..916d70a00c855048e262f9c58b50eeeaae5a4065 100644 (file)
@@ -711,14 +711,14 @@ class Daemon:
             raise XendError('Invalid console id')
         console.disconnect()
 
-    def domain_shutdown(self, dom, reason):
+    def domain_shutdown(self, dom, reason, key=None):
         """Shutdown a domain.
         """
         dom = int(dom)
         ctrl = self.domainCF.getController(dom)
         if not ctrl:
             raise XendError('No domain controller: %s' % dom)
-        ctrl.shutdown(reason)
+        ctrl.shutdown(reason, key)
         return 0
 
     def domain_mem_target_set(self, dom, target):
index c06b260ce115c503331471a97ee0d760cbe6995f..d73a39bff51aa05ef41e12e83ee98fdedd06ef03 100644 (file)
@@ -47,7 +47,8 @@ class SrvDomain(SrvDir):
     def op_shutdown(self, op, req):
         fn = FormFn(self.xd.domain_shutdown,
                     [['dom', 'str'],
-                     ['reason', 'str']])
+                     ['reason', 'str'],
+                     ['key', 'int']])
         val = fn(req.args, {'dom': self.dom.id})
         req.setResponseCode(http.ACCEPTED)
         req.setHeader("Location", "%s/.." % req.prePathURL())
index 4e1baf64dee3865ce540df927a07f1450a27ab69..17483dcc42568fb5f6b487a0552a83a099722a06 100644 (file)
@@ -28,7 +28,8 @@ class DomainController(controller.Controller):
     """
     reasons = {'poweroff' : 'shutdown_poweroff_t',
                'reboot'   : 'shutdown_reboot_t',
-               'suspend'  : 'shutdown_suspend_t' }
+               'suspend'  : 'shutdown_suspend_t',
+               'sysrq'    : 'shutdown_sysrq_t' }
 
     def __init__(self, factory, dom):
         controller.Controller.__init__(self, factory, dom)
@@ -36,16 +37,19 @@ class DomainController(controller.Controller):
         self.addMethod(CMSG_MEM_REQUEST, 0, None)
         self.registerChannel()
 
-    def shutdown(self, reason):
+    def shutdown(self, reason, key=None):
         """Shutdown a domain.
 
         reason shutdown reason
+        key    sysrq key (only if reason is 'sysrq')
         """
         msgtype = self.reasons.get(reason)
         if not msgtype:
             raise XendError('invalid reason:' + reason)
-        msg = packMsg(msgtype, {})
-        self.writeRequest(msg)
+        extra = {}
+        if reason == 'sysrq': extra['key'] = key
+        print extra
+        self.writeRequest(packMsg(msgtype, extra))
 
     def mem_target_set(self, target):
         """Set domain memory target in pages.
index 081dd9ce3274724cfc17e392de6f4777ff72d17b..35f9db986e03df1d75a270ef8112000d67e435a4 100644 (file)
@@ -197,10 +197,12 @@ CMSG_SHUTDOWN = 6
 CMSG_SHUTDOWN_POWEROFF  = 0
 CMSG_SHUTDOWN_REBOOT    = 1
 CMSG_SHUTDOWN_SUSPEND   = 2
+CMSG_SHUTDOWN_SYSRQ     = 3
 
 STOPCODE_shutdown       = 0
 STOPCODE_reboot         = 1
 STOPCODE_suspend        = 2
+STOPCODE_sysrq          = 3
 
 shutdown_formats = {
     'shutdown_poweroff_t':
@@ -211,6 +213,9 @@ shutdown_formats = {
 
     'shutdown_suspend_t':
     (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SUSPEND),
+    
+    'shutdown_sysrq_t':
+    (CMSG_SHUTDOWN, CMSG_SHUTDOWN_SYSRQ)
     }
 
 msg_formats.update(shutdown_formats)
index e7454e507af0912be7af0c743e517cfa48660c8e..411da44106773c6423fe5411323815dff435bb77 100644 (file)
@@ -11,7 +11,7 @@ from xen.xend import PrettyPrint
 from xen.xend import sxp
 from xen.xend.XendClient import XendError, server
 from xen.xend.XendClient import main as xend_client_main
-from xen.xm import create, destroy, migrate, shutdown
+from xen.xm import create, destroy, migrate, shutdown, sysrq
 from xen.xm.opts import *
 
 class Group:
@@ -401,6 +401,19 @@ class ProgShutdown(Prog):
 
 xm.prog(ProgShutdown)
 
+class ProgSysrq(Prog):
+    group = 'domain'
+    name = "sysrq"
+    info = """Send a sysrq to a domain."""
+
+    def help(self, args):
+        sysrq.main([args[0], '-h'])
+    
+    def main(self, args):
+        sysrq.main(args)
+
+xm.prog(ProgSysrq)
+
 class ProgPause(Prog):
     group = 'domain'
     name = "pause"
diff --git a/tools/python/xen/xm/sysrq.py b/tools/python/xen/xm/sysrq.py
new file mode 100644 (file)
index 0000000..44827af
--- /dev/null
@@ -0,0 +1,39 @@
+# (C) Matthew Bloch <matthew@bytemark.co.uk> 2004
+
+"""Domain shutdown.
+"""
+import string
+import sys
+import time
+
+from xen.xend.XendClient import server
+from xen.xm.opts import *
+
+DOM0_NAME = 'Domain-0'
+DOM0_ID = '0'
+
+gopts = Opts(use="""[DOM] [letter]
+
+Sends a Linux sysrq to a domain.
+""")
+
+gopts.opt('help', short='h',
+         fn=set_true, default=0,
+         use="Print this help.")
+
+def sysrq(dom, req):
+    server.xend_domain_shutdown(dom, 'sysrq', req)
+
+def main(argv):
+    opts = gopts
+    args = opts.parse(argv)
+    if opts.vals.help:
+        opts.usage()
+        return
+        
+    # no options for the moment
+    if len(args) < 1: opts.err('Missing domain')
+    if len(args) < 2: opts.err('Missing sysrq character')
+    dom = args[0]
+    req = ord(args[1][0])
+    sysrq(dom, req)